package com.syh.jn.scm.domain.supplier.entity.base.downstream;

import cn.redscarf.commons.util.bean.ExtBeanUtils;
import cn.redscarf.commons.util.other.ExtAssert;
import cn.redscarf.commons.util.validator.ValidationUtils;
import com.syh.core.ddd.domain.AbstractSimpleAggregate;
import com.syh.jn.scm.dto.supplier.base.downstream.DownstreamPriceTemplateMto;
import com.syh.jn.scm.dto.supplier.base.downstream.DownstreamPriceTemplateSto;
import com.syh.jn.scm.exception.BusinessException;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 下游商品价格模板
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class DownstreamPriceTemplate extends AbstractSimpleAggregate<Long> {
  public DownstreamPriceTemplate() {};

  /**
   * 创建模板
   * @param sto
   */
  public DownstreamPriceTemplate(DownstreamPriceTemplateSto sto) {
    ExtAssert.notNull(sto, "对象为空");
    ValidationUtils.validate(sto);
    //系统默认生成字段
    this.createTimeStamp = System.currentTimeMillis();
    this.status = Short.valueOf("1");

    ExtBeanUtils.copyProperties(sto, this);
  }

  /**
   * 修改模板
   * @param mto
   */
  public void modify(DownstreamPriceTemplateMto mto) {
    ExtAssert.notNull(mto, "对象为空");
    ValidationUtils.validate(mto);
    ExtBeanUtils.copyProperties(mto, this,false);
    this.lastUpdateTimeStamp = System.currentTimeMillis();
  }

  /**
   * 数据销毁
   */
  public void destroy() {
    if (this.status.equals(Short.valueOf("1"))) {
      throw new BusinessException("模板已启用,删除失败!");
    }
  }

  /**
   * 启用
   */
  public void enabled() {
    this.status = Short.valueOf("1");
  }

  /**
   * 停用
   */
  public void disabled() {
    this.status = Short.valueOf("-1");
  }

  /**
   * 模板名
   */
  private String name;
  /**
   * 排序等级
   */
  private Integer orderLevel;
  /**
   * 归属id
   */
  private Long businessEntityId;
  /**
   * 描述
   */
  private String attachNote;
  /**
   * 是否可用: -1停用,1可用
   */
  private Short status;
  /**
   * 创建人id
   */
  private Long brokerageId;
}
